package com.student.dong.controller;

import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.system.api.model.LoginUser;
import com.student.dong.domain.AlgsStudent;
import com.student.dong.entity.AlgsCourseSelectionRecord;
import com.student.dong.entity.AlgsCurriculaVarible;
import com.student.dong.service.IAlgsCurriculaVaribleService;
import com.student.dong.service.IAlgsStudentService;
import com.student.dong.service.UserService;
import com.student.dong.utils.Result;
import com.student.dong.vo.CurriculaVaribleVo;
import com.student.dong.vo.LabReportVo;
import com.student.dong.vo.StudentVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.core.web.page.TableDataInfo;
import java.util.List;

import static com.ruoyi.common.core.utils.PageUtils.startPage;

/**
 * @Program: animalSystem->AlgsCurriculaVaribleController
 * @Description:
 * @Author: donghang
 * @Date: 2023-03-20 14:34
 * @Version： 1.0
 **/
@RestController
@RequestMapping("/CurriculaVarible")
public class AlgsCurriculaVaribleController extends BaseController {

    @Autowired
    private IAlgsCurriculaVaribleService curriculaVaribleService;

    @Autowired
    private IAlgsStudentService algsStudentService;

    @Autowired
    private UserService userService;


    @GetMapping("/list")
    public TableDataInfo list() {
        startPage();
        List<CurriculaVaribleVo> list = curriculaVaribleService.selAll();
        Long userId = SecurityUtils.getUserId();
        algsStudentService.selectAlgsStudentByStudentId(userId);
        return getDataTable(list);
    }


    @PutMapping("/addClass")
    public AjaxResult addClass(@RequestBody LabReportVo curriculaVaribleVo) {
        Integer curriculaVaribleId = curriculaVaribleVo.getCurriculaVaribleId();
        String curriculaVaribleBy2 = curriculaVaribleVo.getCurriculaVaribleBy2();
        int i = curriculaVaribleService.addClass(curriculaVaribleId, curriculaVaribleBy2);
        if(i == 1){
            return AjaxResult.error(910,"当前课程已满员");
        } else if(i == 3){
            return AjaxResult.error(911,"当前课程已选择，请勿重复添加！");
        }
        return AjaxResult.success();
    }
}
